<?php

namespace App\Transformers;

use App\Models\Collect;
use League\Fractal\TransformerAbstract;


class CollectTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['tags', 'pictuers'];

    public function transform(Collect $collect)
    {
        return [
            'id' => $collect->id,
            'title' => $collect->title,

            'created_at' => $collect->created_at ? $collect->created_at->toDateTimeString() : now()->toDateTimeString(),
            'updated_at' => $collect->updated_at ? $collect->updated_at->toDateTimeString() : now()->toDateTimeString(),
        ];
    }

    public function includeTags(Collect $collect)
    {
        return $this->collection($collect->pictuers, new PictuerTransformer());
    }
}
